package com.edu.exam.entity.assessment.plan;

import com.edu.exam.enums.PlanStatus;
import com.edu.exam.enums.exam.ExamType;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 考试计划实体类
 * 所属模块：B-05 考核计划管理模块
 * 对应数据库表：exam_plan
 *
 * <p>考试计划制定子模块的核心实体，记录考试计划的基本信息和状态。
 * 每个计划对应一个具体的考试安排，包含计划基本信息、时间安排、
 * 状态管理、审核流程等完整内容。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Table(name = "exam_plan")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExamPlan {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 考试计划编码
     */
    @Column(name = "plan_code", unique = true, length = 50, nullable = false)
    private String planCode;

    /**
     * 考试计划名称
     */
    @Column(name = "plan_name", length = 100, nullable = false)
    private String planName;

    /**
     * 学年信息
     */
    @Column(name = "academic_year", length = 10, nullable = false)
    private String academicYear;

    /**
     * 学期信息
     */
    @Column(name = "semester", length = 20, nullable = false)
    private String semester;

    /**
     * 考试类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "exam_type", length = 20, nullable = false)
    private ExamType examType;

    /**
     * 计划状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "plan_status", length = 20, nullable = false)
    private PlanStatus planStatus;

    /**
     * 考试开始日期
     */
    @Column(name = "start_date", nullable = false)
    private LocalDate startDate;

    /**
     * 考试结束日期
     */
    @Column(name = "end_date", nullable = false)
    private LocalDate endDate;

    /**
     * 创建者ID
     */
    @Column(name = "creator_id", nullable = false)
    private Long creatorId;

    /**
     * 创建者姓名
     */
    @Column(name = "creator_name", length = 100)
    private String creatorName;

    /**
     * 审批者ID
     */
    @Column(name = "approver_id")
    private Long approverId;

    /**
     * 审批者姓名
     */
    @Column(name = "approver_name", length = 100)
    private String approverName;

    /**
     * 计划描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 计划详细内容（JSON格式）
     */
    @Column(name = "plan_content", columnDefinition = "TEXT")
    private String planContent;

    /**
     * 适用院系
     */
    @Column(name = "applicable_department", length = 200)
    private String applicableDepartment;

    /**
     * 适用专业
     */
    @Column(name = "applicable_major", length = 200)
    private String applicableMajor;

    /**
     * 适用年级
     */
    @Column(name = "applicable_grade", length = 100)
    private String applicableGrade;

    /**
     * 计划优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 计划版本
     */
    @Column(name = "version", length = 20)
    private String version;

    /**
     * 模板ID
     */
    @Column(name = "template_id")
    private Long templateId;

    /**
     * 模板名称
     */
    @Column(name = "template_name", length = 100)
    private String templateName;

    /**
     * 审核流程ID
     */
    @Column(name = "audit_process_id")
    private Long auditProcessId;

    /**
     * 当前审核节点
     */
    @Column(name = "current_audit_node", length = 100)
    private String currentAuditNode;

    /**
     * 删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审批时间
     */
    @Column(name = "approval_time")
    private LocalDateTime approvalTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 生效时间
     */
    @Column(name = "effective_time")
    private LocalDateTime effectiveTime;

    /**
     * 失效时间
     */
    @Column(name = "expiry_time")
    private LocalDateTime expiryTime;

    /**
     * 考试科目列表
     */
    @OneToMany(mappedBy = "examPlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ExamSubject> examSubjects;

    /**
     * 计划版本列表
     */
    @OneToMany(mappedBy = "examPlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ExamPlanVersion> versions;

    /**
     * 审核记录列表
     */
    @OneToMany(mappedBy = "examPlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ExamPlanAuditRecord> auditRecords;

}
